package com.woniu.commons.model;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Result<T> implements Serializable {
    private String msg;
    private Integer code;
    private T data;



    public static Result<?> getResult(){
        Result<?> re = new Result<>();
        re.setCode(200);
        re.setMsg("成功");
        return re;
    }
    public static<S> Result<S> newInstance(Class<S> type){
        Result<S> re = new Result<>();
        re.setCode(200);
        re.setMsg("成功");
        return re;
    }

    public static<S> Result<List<S>> newListInstance(Class<S> type){
        Result<List<S>> re = new Result<>();
        re.setCode(200);
        re.setMsg("成功");
        return re;
    }
    public static<S> Result<Page<S>> newPageInstance(Class<S> type){
        Result<Page<S>> re = new Result<>();
        re.setCode(200);
        re.setMsg("成功");
        return re;
    }

    public static<S> Result<Set<S>> newSetInstance(Class<S> type){
        Result<Set<S>> re = new Result<>();
        re.setCode(200);
        re.setMsg("成功");
        return re;
    }

    public  static  <S,K>Result<Map<S,K>>getMapResult(Class<S> type, Class<K>valueType){
        Result<Map<S,K>> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return  result;
    }

    public  static  <S,K>Result<Map<S,List<K>>>getMapListResult(Class<S> type, Class<K>valueType){
        Result<Map<S,List<K>>> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return  result;
    }
    public  static  <S,K>Result<Map<S,Set<K>>>getMapSetResult(Class<S> type, Class<K>valueType){
        Result<Map<S,Set<K>>> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return  result;
    }





    public String getMsg() {
        return msg;
    }

    public Result<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public Result<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }





}
